<?php
namespace app\common\controller;

use think\Controller;
use \app\common\libs\WeixinHelper;

ABSTRACT class BaseController extends Controller
{
    protected $beforeActionList = [
        'accessCheck',
    ];

    protected function accessCheck() {
        // session('userinfo.role', 99);
        // session('userinfo.openid', 'oT6Uf0tZsHPrZP62aBBTbmK03oDs');
        // session('userinfo.mobile', '18500225853');

        if(!session('?userinfo')) {
            if(is_weixin()) {
                $appid = config('weixin.appid');
                $callback = request()->domain().config('weixin.callback');

                header('location:'.WeixinHelper::getCodeForWeb($appid, $callback));
            } else {
                $this->redirect('back/login/login');
            }
            die;
        } else {
            $request = \think\Request::instance();
            if($request->module() === 'back' && session('userinfo.role') != 99) {
                $this->redirect('index/member/index');
            }
        }
    }

    function __toString() {
        return get_class($this);
    }
}
